import requests

HOST = 'http://countdown.api.tfl.gov.uk/interfaces/ura/stream_V1'
DOWNLOAD = False

HEADERS = {
    "method": "GET",
    "version": "HTTP/1.1",
    "accept": "*/*",
    "accept-encoding": "gzip, deflate",
    "accept-language": "en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4",
    "content-type": "application/x-www-form-urlencoded;charset=UTF-8",
    "User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.6)",
    "Connection":"keep-alive",
    "Upgrade-Insecure-Requests":"1",
    "Authorization":'Digest username="LiveBus78579", realm="URA", nonce="35af86b9a6a06a58584778408c2a46fd", uri="/interfaces/ura/stream_V1", response="68345bc490c11e3fb4ec2b71bd70b96c", opaque="b56b8d13e2c07eb2dff35fc1d233b3b4", qop=auth, nc=00000002, cnonce="e72aa905a663fe58"'
}


def raw_connect():
    return requests.session()


if __name__ == '__main__':
    conn = raw_connect()
    response = conn.get("%s" % (HOST), headers=HEADERS, stream=True)
    if DOWNLOAD:
        f = open("123.txt", "wb")
    for chunk in response.iter_content(chunk_size=512):
        if chunk:
            if DOWNLOAD:
                f.write(chunk)
            print(chunk.decode(encoding='utf-8', errors="strict"), end='')
    print(response.text)